<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>资金归集</cite></a>
        <a><cite>支付宝分账</cite></a>
        <a><cite>收款账户</cite></a>
    </span>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">收款账户列表</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-row">
                    <div class="layuiAdmin-btns" style="margin-bottom: 10px;">
                        <a class="layui-btn create" data-type="all" data-events="create"><i class="layui-icon layui-icon-add-1"></i>新增收款账号</a>
                    </div>
                </div>
                <table class="layui-hide center" id="cList" lay-filter="cList"></table>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['table','util', 'form', 'admin'], function(){
        var table = layui.table
        ,$ = layui.$
        ,form = layui.form
        ,view = layui.view
        ,admin = layui.admin
        ,element = layui.element;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        //标题内容模板
        var tplTitle = function(d){
            return "<a class='layui-btn layui-btn-xs' lay-event='edit'><i class='layui-icon layui-icon-edit'></i>编辑</a>";
        };

        var tplStatus = function(d){
            var checkedHtml = " id='"+d.id+"' ";
            if(d.status == 1) {
                checkedHtml += " checked";
            }
            return '<input type="checkbox" lay-filter="statusSwitch" lay-skin="switch" '+checkedHtml+' lay-text="启用|停用">';
        };

        table.render({
            elem: '#cList'
            ,url: layui.setter.baseUrl + '/config/pay_cash_coll/list'
            ,where: { access_token: layui.data(layui.setter.tableName).access_token, belongPayAccountId : 0 }
            ,id: 'tableReload'
            ,cols: [[
                {field:'transInUserName', title: '分账收入方姓名'}
                ,{field:'transInUserAccount',  title: '分账收入方账号'}
                ,{field:'transInUserId',  title: '分账收入方用户ID'}
                ,{title: '分账百分比', templet: "<span>{{ d.transInPercentage }}% </span>"}
                ,{field:'belongPayAccountId',  title: '所属支付子账户ID'}
                ,{title: '状态',templet: tplStatus }
                ,{field:'edite', width: 100, fixed: "right", title: '操作', templet: tplTitle }
            ]]
            ,page: true
            ,skin: 'line'
        });

        //监听工具条
        table.on('tool(cList)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                view.xxpayPopup("编辑", "cash_coll/alipay_coll/pay_cash_coll/update", {id: data.id}, {area:['70%','55%']});
            }
        });

        $('.create').click(function(){
            view.xxpayPopup("新增收款账号", "cash_coll/alipay_coll/pay_cash_coll/create", {null: null}, {area:['70%','60%']});
        });

        form.on('switch(statusSwitch)', function(data){

            var id = $(data.elem).attr('id');
            var updateState = data.elem.checked ? "1" : "0";
            var loadingIndex = layer.load();
            admin.req({
                type: "POST",
                url: layui.setter.baseUrl + '/config/pay_cash_coll/updateStatus',
                data: {id: id, status: updateState},
                success: function(res){
                    if(res.code == 0) {
                        table.reload('tableReload');
                    }
                },
                complete:function(){
                    layer.close(loadingIndex);
                }
            });
        });

        // 渲染表单
        form.render();
    });
    
</script>
